import { createLogger, defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
const logger = createLogger();

// https://vite.dev/config/
export default defineConfig({
  plugins: [react()],
  build: {
    minify: false,
    sourcemap: true,
    cssMinify: false,
    target: 'esnext',
    rollupOptions: {
      treeshake: false,
      output: {
        format: 'es',
        entryFileNames: `[name].js`,
        chunkFileNames: `[name]-[hash].js`,
        assetFileNames: `[name].[ext]`,
        indent: '  ',
        compact: false,
        manualChunks(id) {
          logger.info('######:'+id)
          if (id.includes('node_modules')) {
            // 获取包名
            const match = id.match(/node_modules\/.store\/([^/]+)/);
            // 将每个包单独打包
            return match? `vendor-${match[1]}`: 'vendor';
          }
          // 非 node_modules 的文件返回 null，将被打包到主文件中
          return null;
        }
      }
    }
  }
})
